package com.lixin.juc;

public class MainApplication {

    public static void main(String[] args) {
        //System.out.println(Runtime.getRuntime().availableProcessors());

        // 测试多个线程访问同一个资源
        /*Ticket ticket = new Ticket();

        new Thread(() -> {
            for (int i = 1; i <= 5000; i++) {
                ticket.sale();
            }
        }, "AThread").start();

        new Thread(() -> {
            for (int i = 1; i <= 5000; i++) {
                ticket.sale();
            }
        }, "BThread").start();

        new Thread(() -> {
            for (int i = 1; i <= 5000; i++) {
                ticket.sale();
            }
        }, "CThread").start();*/

        // 测试生产者消费者（多个线程）
        /*PC pc = new PC();

        new Thread(() -> {
            for (int i = 1; i <= 50; i++) pc.increment();
        }, "A-Thread").start();

        new Thread(() -> {
            for (int i = 1; i <= 50; i++) pc.decrement();
        }, "B-Thread").start();

        new Thread(() -> {
            for (int i = 1; i <= 50; i++) pc.increment();
        }, "C-Thread").start();

        new Thread(() -> {
            for (int i = 1; i <= 50; i++) pc.decrement();
        }, "D-Thread").start();*/

        // 测试多线程精准唤醒
        Exact exact = new Exact();

        new Thread(() -> {
            for (int i = 1; i <= 20; i++) {
                exact.taskA();
            }
        }, "").start();

        new Thread(() -> {
            for (int i = 1; i <= 20; i++) {
                exact.taskB();
            }
        }, "").start();

        new Thread(() -> {
            for (int i = 1; i <= 20; i++) {
                exact.taskC();
            }
        }, "").start();
    }

}